package com.jindy.module.oaClockApproval.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaDepartApproval.controller.SyOaDepartController;
import com.jindy.module.oaDepartApproval.domain.SyOaDepart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaClockApproval.domain.SyOaClock;
import com.jindy.module.oaClockApproval.service.ISyOaClockService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 补卡审批Controller
 * 
 * @author jindy
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/module/oaClockApproval")
public class SyOaClockController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaClockController.class);

    @Autowired
    private ISyOaClockService syOaClockService;

    /**
     * 查询补卡审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaClockApproval:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaClock syOaClock)
    {
        startPage();
        List<SyOaClock> list = syOaClockService.selectSyOaClockList(syOaClock);
        return getDataTable(list);
    }

    /**
     * 导出补卡审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaClockApproval:export')")
    @Log(title = "补卡审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaClock syOaClock)
    {
        List<SyOaClock> list = syOaClockService.selectSyOaClockList(syOaClock);
        ExcelUtil<SyOaClock> util = new ExcelUtil<SyOaClock>(SyOaClock.class);
        util.exportExcel(response, list, "补卡审批数据");
    }

    /**
     * 获取补卡审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaClockApproval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaClockService.selectSyOaClockById(id));
    }

    /**
     * 新增补卡审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaClockApproval:add')")
    @Log(title = "补卡审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaClock syOaClock)
    {
        return toAjax(syOaClockService.insertSyOaClock(syOaClock));
    }

    /**
     * 修改补卡审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaClockApproval:edit')")
    @Log(title = "补卡审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaClock syOaClock)
    {
        return toAjax(syOaClockService.updateSyOaClock(syOaClock));
    }

    /**
     * 删除补卡审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaClockApproval:remove')")
    @Log(title = "补卡审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaClockService.deleteSyOaClockByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "补卡审批", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaClock syOaClock = syOaClockService.selectSyOaClockById(id);
            syOaClockService.submitApply(syOaClock);
        } catch (Exception e) {
            LOGGER.error("补卡审批提交申请出错",e);
            return error("补卡审批提交申请出错：" + e.getMessage());
        }
        return success();
    }
}
